<?php

use source\core\back\BackApplication;
use source\aii;
use source\libs\Common;

defined('DS') or define('DS',DIRECTORY_SEPARATOR);
defined('BACKEND_APP_PATH') or define('BACKEND_APP_PATH',__DIR__);
defined('WEB_APP_ROOT') or define('WEB_APP_ROOT',dirname(__DIR__));
// comment out the following two lines when deployed to production
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', true); // hewei  open default : 'dev'

if(!file_exists(WEB_APP_ROOT.DS.'data'.DS.'install.lock')){
    return include(WEB_APP_ROOT.DS.'install'.DS.'index.php');
}


require (WEB_APP_ROOT .DS. 'vendor'.DS.'autoload.php');
require (WEB_APP_ROOT .DS.'vendor'.DS.'yiisoft'.DS.'yii2'.DS.'Yii.php');

require (WEB_APP_ROOT . DS .'source'.DS.'override.php');

require (WEB_APP_ROOT . DS.'data'.DS.'config'.DS.'bootstrap.php');
require (WEB_APP_ROOT . DS.'backend'.DS.'config'.DS.'bootstrap.php');


$config = yii\helpers\ArrayHelper::merge(
    require(WEB_APP_ROOT .DS. 'data'.DS.'config'.DS.'main.php'),
    require(WEB_APP_ROOT . DS.'data'.DS.'config'.DS.'main-local.php'),
    require(WEB_APP_ROOT . DS.'backend'.DS.'config'.DS.'main.php'),
    require(WEB_APP_ROOT . DS.'backend'.DS.'config'.DS.'main-local.php')
);

Common::checkInstall($config);

$app = new BackApplication($config);
$app->defaultRoute='/site/index';

return $app ;